package com.tjp.eight.ui.fragment.homepage;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.ResultModel;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.utils.AppUtils;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/2/18.
 */
public class HomePagePresenter extends BasePresenterImpl<HomePageView> {
    private HomePageService hService = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(HomePageService.class);

    public HomePagePresenter(HomePageView view) {
        attachView(view);
    }

    public void loadAction(String pJson) {
        RequestBody requestBody = AppUtils.getRequestBody(pJson);
        addSubscription(hService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeRModel>() {
            @Override
            public void onSuccess(HomeRModel model) {
                view.loadActionSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void loadComment(String pJson) {
        RequestBody requestBody = AppUtils.getRequestBody(pJson);
        addSubscription(hService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeRModel>() {
            @Override
            public void onSuccess(HomeRModel model) {
                view.loadCommentSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void loadShare(String pJson) {
        RequestBody requestBody = AppUtils.getRequestBody(pJson);
        addSubscription(hService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeRModel>() {
            @Override
            public void onSuccess(HomeRModel model) {
                view.loadShareSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void loadCollection(String pJson) {
        RequestBody requestBody = AppUtils.getRequestBody(pJson);
        addSubscription(hService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeRModel>() {
            @Override
            public void onSuccess(HomeRModel model) {
                view.loadCollectionSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void unCollection(String puJson) {
        RequestBody body = AppUtils.getRequestBody(puJson);
        addSubscription(hService.removecollect(body), new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.unCollection(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
